//引入集合模型
const { errorModel } = require("../models/errorModel");


//获取所有数据
// async function getAllError (req, res, next) {

//     let Errors = await errorModel.find({}).populate("errorQuestions_id").populate(" user_id")
//     res.send({code:1, Errors});
// }

async function getAllError(req, res, next) {
    console.log(req.get('Authorization'));
    const { pageNum, pageSize } = req.body
    console.log(pageNum, pageSize);
    // 获取到当前查询的文档所有的总条数
    const total = await errorModel.countDocuments()
     const pages = Math.ceil(total/pageSize)
    // 计算一共多少页
    // const pages = Math.ceil(total/pageSize)
    console.log(total);
    let ErrorQuestions = await errorModel.find({}).populate({
        path: "errorQuestions_id",
        populate: {
            path: "KnowledgePointId"
        }
    }).populate("user_id").skip((pageNum - 1) * pageSize).limit(parseInt(pageSize));
    res.send({
        code: 1,
        ErrorQuestions,
        total,
        pages
    });
    // 将获取的数据传递给View文件夹下面模板引擎，让模板引擎拼接内容，拼接好的页面返回
}
module.exports = { getAllError }